<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="70px">

      <el-form-item label="提交人" prop="committer">
        <el-input
          v-model="queryParams.committer"
          placeholder="请输入提交人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="反馈类型" prop="feedBackType">
        <el-select v-model="queryParams.feedBackType" placeholder="请选择反馈类型" clearable>
          <el-option
            v-for="dict in dict.type.feedback_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="客户端" prop="feedBackClient">
        <el-select v-model="queryParams.feedBackClient" placeholder="请选择反馈客户端" clearable>
          <el-option
            v-for="dict in dict.type.feedback_client"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否回复" prop="isReplay">
        <el-select v-model="queryParams.isReplay" placeholder="请选择是否回复" clearable>
          <el-option
            v-for="dict in dict.type.sys_is_enable"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="回复人" prop="replayer">
        <el-input
          v-model="queryParams.replayer"
          placeholder="请输入回复人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cms:feedback:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="feedbackList" >
      <el-table-column label="提交人" align="center" prop="committer" />
      <el-table-column label="联系方式" align="center" prop="contactNumber" />
      <el-table-column label="内容" align="center" :show-overflow-tooltip=true prop="content" />
      <el-table-column label="更多建议" align="center" :show-overflow-tooltip=true prop="contentMore" />
      <el-table-column label="反馈类型" align="center" prop="feedBackType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.feedback_type" :value="scope.row.feedBackType"/>
        </template>
      </el-table-column>
      <el-table-column label="反馈客户端" align="center" prop="feedBackClient">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.feedback_client" :value="scope.row.feedBackClient"/>
        </template>
      </el-table-column>
      <el-table-column label="是否回复" align="center" prop="isReplay">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_is_enable" :value="scope.row.isReplay"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="回复时间" align="center" prop="replayTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.replayTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="回复人" align="center" prop="replayer" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleReplay(scope.row)"
            v-if="scope.row.isReplay == 0"
            v-hasPermi="['cms:feedback:replay']"
          >回复</el-button>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleDetail(scope.row)"
            v-hasPermi="['cms:feedback:query']"
          >查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 回复对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="50%" append-to-body>
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>反馈信息</span>
        </div>
        <el-row>
          <el-col :span="12">
            <div class="replay-item">
              <div class="replay-item-label">提交人:</div>
              <div class="replay-item-val">
                {{feedBack.committer}}
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <div class="replay-item">
              <div class="replay-item-label">反馈客户端:</div>
              <div class="replay-item-val">
                <template >
                  <dict-tag :options="dict.type.feedback_client" :value="feedBack.feedBackClient"/>
                </template>
              </div>
            </div>
          </el-col>
          <el-col :span="12">
            <div class="replay-item">
              <div class="replay-item-label">反馈类型:</div>
              <div class="replay-item-val">
                <template >
                  <dict-tag :options="dict.type.feedback_type" :value="feedBack.feedBackType"/>
                </template>
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="replay-item">
              <div class="replay-item-label">反馈内容:</div>
              <div class="replay-item-val">
                {{feedBack.content}}
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="replay-item">
              <div class="replay-item-label">更多建议:</div>
              <div class="replay-item-val">
                {{feedBack.contentMore}}
              </div>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="replay-item">
              <div class="replay-item-label">图片:</div>
              <div class="replay-item-val">
                <image-preview :src="feedBack.imgs" :width="100"></image-preview>
              </div>
            </div>
          </el-col>
        </el-row>
      </el-card>
      <el-card class="box-card" style="margin-top: 10px">
        <div slot="header" class="clearfix">
          <span>反馈回复</span>
        </div>
        <el-form v-if="feedBack.isReplay == 0" ref="form" :model="form" :rules="rules" label-width="80px">
          <el-form-item label="回复内容">
            <editor v-model="form.replayContent" :min-height="192"/>
          </el-form-item>
          <el-form-item label="备注" prop="remark">
            <el-input v-model="form.remark" placeholder="请输入备注" />
          </el-form-item>
        </el-form>
        <div v-else>
          <el-row>
            <el-col :span="24">
              <div class="replay-item">
                <div class="replay-item-label">回复信息:</div>
                <div class="replay-item-val" v-html="feedBack.replayContent">
<!--                  {{feedBack.committer}}-->
                </div>
              </div>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <div class="replay-item">
                <div class="replay-item-label">备注:</div>
                <div class="replay-item-val" >
                                    {{feedBack.remark}}
                </div>
              </div>
            </el-col>
          </el-row>
        </div>
      </el-card>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="feedBack.isReplay == 0" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listFeedback, getFeedback, delFeedback, addFeedback, replayFeedback } from "@/api/cms/feedback";
export default {
  name: "Feedback",
  dicts: ['feedback_type','feedback_client','sys_is_enable'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 意见反馈表格数据
      feedbackList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        committerId: null,
        committer: null,
        feedBackType: null,
        feedBackClient: null,
        deleteFlag: null,
        replayer: null
      },
      // 表单参数
      form: {},
      feedBack: {},
      // 表单校验
      rules: {
      },

    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询意见反馈列表 */
    getList() {
      this.loading = true;
      listFeedback(this.queryParams).then(response => {
        this.feedbackList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        remark: null,
        replayContent: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加意见反馈";
    },
    /** 查看按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getFeedback(id).then(response => {
        this.feedBack = response.data;
        this.open = true;
        this.title = "查看意见反馈";
      });
    },
    /** 回复按钮操作 */
    handleReplay(row) {
      this.reset();
      const id = row.id
      getFeedback(id).then(response => {
        this.feedBack = response.data;
        this.form.id = id;
        this.open = true;
        this.title = "回复意见反馈";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          replayFeedback(this.form).then(response => {
            this.$modal.msgSuccess("回复成功");
            this.open = false;
            this.getList();
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除意见反馈编号为"' + ids + '"的数据项？').then(function() {
        return delFeedback(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('cms/feedback/export', {
        ...this.queryParams
      }, `feedback_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>

<style lang="scss" scoped>
  .replay-item{
    display: flex;
    line-height: 36px;
    text-align: left;
    .replay-item-label{
      flex: 1;
      max-width: 100px;
    }
    .replay-item-val{
      flex: 1;
      text-align: left;
    }
  }
</style>
